package v1

import (
	"github.com/gin-gonic/gin"
	"guns-go/model/request"
	"guns-go/model/response"
	"guns-go/service"
)

// @Tags App
// @Summary 分页获取应用管理列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysAppParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysApp/page [get]
func AppPage(c *gin.Context) {

	var A request.SysAppParam
	_ = c.ShouldBindQuery(&A)

	err, AppPageResult := service.AppPage(&A, c)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(AppPageResult, c)
}

// @Tags App
// @Summary 新增应用
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysAppParam true "新增应用"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysApp/add [post]
func AppAdd(c *gin.Context) {

	var A request.SysAppParam
	_ = c.ShouldBindJSON(&A)

	err := service.AppAdd(&A)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags App
// @Summary 修改应用
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysAppParam true "修改应用"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysApp/edit [post]
func AppEdit(c *gin.Context) {

	var A request.SysAppParam
	_ = c.ShouldBindJSON(&A)

	err := service.AppEdit(&A)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags App
// @Summary 删除应用
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysAppParam true "删除应用"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysApp/delete [post]
func AppDelete(c *gin.Context) {

	var A request.SysAppParam
	_ = c.ShouldBindJSON(&A)

	err := service.AppDelete(&A)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags App
// @Summary 设置默认应用
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysAppParam true "设置默认应用"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysApp/setAsDefault [post]
func SetAsDefault(c *gin.Context) {

	var A request.SysAppParam
	_ = c.ShouldBindJSON(&A)

	err := service.SetAsDefault(&A)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags App
// @Summary 应用列表查询
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysApp/list [get]
func AppList(c *gin.Context) {

	err, info := service.AppList()

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(info, c)
}
